<template>
  <div>
    <!-- //搜索 -->
    <div class="contenInput">
      <el-input
        class="logInput"
        placeholder="Please Input"
        v-model="text"
      />
      <el-button
        type="primary"
        @click="onSearch"
      ><span class="iconfont icon-sousuo"></span>查找</el-button>
    </div>
    <!-- //表格 -->
    <div class="tableBox">
      <el-table
        :data="tableData"
        border
      >
        <el-table-column
          prop="id"
          label="日志ID"
        />
        <el-table-column
          prop="adminId"
          label="管理员ID"
        />
        <el-table-column
          prop="requestId"
          label="请求ID"
        />
        <el-table-column
          prop="group"
          label="API分组"
        />
        <el-table-column
          prop="method"
          label="API方法"
        />
        <el-table-column
          prop="gmtCreate"
          label="操作时间"
        />
      </el-table>
    </div>
    <!-- //分页 -->
    <daily-demo
      v-bind="demo"
      @pages="pages"
      @limits="limits"
    ></daily-demo>
  </div>
</template>

<script>
import http from "@/util/http";
import DailyDemo from "@/components/DailyOperation/Demo.vue";
export default {
  components: {
    DailyDemo,
  },

  data() {
    return {
      demo: {
        page: 10,
        limit: 10,
        total: 100, //分页--总条数
      },
      tableData: [], //列表数据
      text: "",
    };
  },
  created() {
    this.adminLog(); //创建后已经调用函数
  },
  methods: {
    //搜索
    onSearch() {
      this.adminLog();
    },
    //分页---当前页数
    pages(e) {
      console.log(e,456);
      this.demo.page = e;
      this.adminLog();
    },
    // 分页---每页显示条目个数
    limits(e) {
      this.demo.limit = e;
      this.adminLog();
    },
    // 操作日志列表
    adminLog() {
      const data = {
        //列表参数
        _gp: "admin.log",
        _mt: "list",
        page: this.demo.page,
        limit: this.demo.limit,
        targetAdminId: this.text, //管理员ID
      };
      http
        .post(data)
        .then((res) => {
          console.log(res, "操作日志");
          this.tableData = res.data.data.items;
          this.demo.total = res.data.data.total;
          console.log(this.demo.total ,123);
          this.tableData.forEach((item) => {
            let time =
              new Date(item.gmtCreate)
                .toLocaleDateString()
                .replace(/\//, "年")
                .replace(/\//, "月") +
              "日 " +
              new Date(item.gmtCreate)
                .toTimeString()
                .substr(0, 8)
                .replace(/:/, "时")
                .replace(/:/, "分") +
              "秒";
            // console.log(time);
            item.gmtCreate = time;
          });
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style lang="less" scoped>
.contenInput {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  //查找输入框的宽度
  .logInput {
    width: 200px;
    margin-right: 20px;
  }
}
</style>
